<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/12/1 0001
  Time: 上午 9:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>会员级别列表</title>
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <link href="/static/plugins/bootstrap-table/bootstrap-table.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/static/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <link rel="stylesheet" href="/static/css/common.css">
</head>
<body>



<div class="layui-row ">
    <div class="layui-col-md3">
        <div class="layui-form-item">
            <label class="layui-form-label">字典管理</label>
            <div class="layui-input-block">
                <input type="hidden" name="dictIds" id="dictIds">
                <ul id="dictTree" class="ztree"></ul>
            </div>
        </div>
    </div>
    <div class="layui-col-md9">
        <div class="layui-tab layui-tab-card">
            <input type="hidden" name="tabId" id="tabId" value="${param.tabId}">
            <ul class="layui-tab-title">
                <li class="layui-this" id="btn_add">增加</li>
                <li id="btn_edit">编辑</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <form class="layui-form" method="post">
                        <div class="layui-form-item">
                            <label class="layui-form-label">父类名称：</label>
                            <div class="layui-input-inline">
                                <select name="fid" lay-verify="required" lay-search="">
                                    <option>请选择或搜索父类</option>
                                    <c:forEach items="${sysDicts}" var="sysDict">
                                        <option value="${sysDict.id}">${sysDict.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label box-width">类别名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" lay-verify="required" placeholder="请输入类别名称"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label box-width">类别代码：</label>
                            <div class="layui-input-block">
                                <input type="text" name="code" lay-verify="required" placeholder="请输入类别代码"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formadd" >保存</button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="layui-tab-item">
                    <form class="layui-form" method="post">
                        <div class="layui-form-item">
                            <label class="layui-form-label box-width">父类名称：</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="fid" value="${sysdict.id}">
                                <input type="text" name="parentname" id="parentname" lay-verify="parentname"
                                       value="${sysdict.name}" placeholder="请输入父类名称" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label box-width">类别名称：</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="id" value="${sysdict.name}">
                                <input type="text" name="name" value="${sysdict.name}" id="name" lay-verify="required"
                                       placeholder="请输入类别名称" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label box-width">类别代码：</label>
                            <div class="layui-input-block">
                                <input type="text" name="code" value="${sysdict.code}" id="code" lay-verify="required"
                                       placeholder="请输入类别代码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formedit">保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/static/plugins/jquery.js"></script>
<script src="/static/plugins/layui/layui.js"></script>
<script type="text/javascript" src="/static/plugins/ztree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="/static/plugins/ztree/js/jquery.ztree.excheck.js"></script>
<script src="/static/plugins/bootstrap/js/bootstrap.js"></script>
<script src="/static/plugins/bootstrap-table/bootstrap-table.js"></script>
<script src="/static/plugins/bootstrap-table/bootstrap-table-zh-CN.js"></script>

<script>

    layui.use(['element','layer','form'], function(){
        var form = layui.form;
        var element = layui.element;
        var layer = layui.layui;
        //监听提交
        form.on('submit(formadd)', function(data){
            $.ajax({
                url:"/sysdict/add",
                type:"post",
                data:data.field,
                dataType:'json',
                success:function () {
                    debugger
                    layer.msg("保存成功")
                },
                error:function () {
                    layer.msg("服务器忙，请稍候再试")
                }
            })
        })
        form.on('submit(formedit)', function(data){
            $.ajax({
                url:"/sysdict/edit",
                type:"post",
                data:data.field,
                dataType:'json',
                success:function () {
                    debugger
                    layer.msg("修改成功")
                },
                error:function () {
                    layer.msg("服务器忙，请稍候再试")
                }
            })
        })
        var setting = {
            check: {
                chkboxType : { "Y" : "", "N" : "ps" },
                enable: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            }
        };
        var id = $("#id").val();
        $.ajax({
            url:"/sysdict/tree",
            type:'get',
            dataType:'json',
            data:{roleId:id},
            success:function(msg){
                if(msg.code == 1) {
                    var data = msg.data;
                    $.fn.zTree.init($("#dictTree"), setting, data);
                }
            },
            error:function(e){
                console.log("权限树加载失败");
            }
        });
    });
</script>
</body>
</html>
